package com.cpa.admin.mapper;

import com.cpa.admin.base.BaseMapper;
import com.cpa.admin.model.UserDo;
import com.cpa.admin.vo.UserVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* Created by Mybatis Generator 2018/11/04
 * @author zhao
 */
@Mapper
public interface UserMapper extends BaseMapper<UserDo> {


    /**
     * 通过用户名查找用户信息
     * @param username
     * @return
     */
    @Select("select * from user u where u.username = #{username} and u.delete_flag = 0 ")
    UserDo findByUsername(String username);


    /**
     * 根据用户名获取密码
     * @param username
     * @return
     */
    @Select("select u.password from user u where u.username = #{username} and u.delete_flag = 0 ")
    String getPasswordByUsername(String username);


    @Select("select u.is_admin from user u where u.delete_flag = 0 and u.username = #{username}")
    Boolean isAdmin(String username);

    /**
     * 列表
     * @return
     */
    @Select("<script>" +
            "select * from user_list l where 1=1 " +
            "<if test='username!=null'> " +
            "and l.username like #{username}" +
            "</if> "
            + "</script> ")
    List<UserVo> findAllVoByView(@Param("username") String username);


    @Select("select u.id from user u where u.delete_flag =0 and u.username = #{username} ")
    String getId(String username);
}